package com.swifty.toptoastbar.slice;

import com.swifty.toptoastbar.BottomToast;
import com.swifty.toptoastbar.ResourceTable;
import com.swifty.toptoastbar.Toast;
import com.swifty.toptoastbar.TopToast;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;

public class MainAbilitySlice extends AbilitySlice {

    private Toast windowToast;
    private Toast toast;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        windowToast = TopToast.make(this, "HELLO WORLD!!!!", Toast.LENGTH_SHORT);
        toast = TopToast.make((ComponentContainer) findComponentById(ResourceTable.Id_parent), "HELLO WORLD!!!!", Toast.LENGTH_SHORT);

        findComponentById(ResourceTable.Id_button).setClickedListener(component -> {
            //top
            toast.show();
        });

        findComponentById(ResourceTable.Id_button2).setClickedListener(component -> {
            //bottom
            BottomToast.make((ComponentContainer) findComponentById(ResourceTable.Id_parent), "HELLO WORLD!!!!", Toast.LENGTH_SHORT).show();
        });

        findComponentById(ResourceTable.Id_button3).setClickedListener(component -> {
            //window top
            windowToast.show();
        });

        findComponentById(ResourceTable.Id_button4).setClickedListener(component -> {
            //window bottom
            BottomToast.make(this, "HELLO WORLD!!!!", Toast.LENGTH_SHORT).show();
        });
    }
}
